//
//  ViewController.m
//  PopOver
//
//  Created by admin on 5/10/15.
//  Copyright (c) 2015 Module4. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
            

@end

@implementation ViewController
            
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)clickMe:(id)sender {
    if (self.myMessage == nil) {
        
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        self.myMessage = [story instantiateViewControllerWithIdentifier:@"popOver"];
        self.myMessage.preferredContentSize = CGSizeMake(200, 100);
    }
    UIButton *clickMe = (UIButton *)sender;
    if (self.messagePopover == nil) {
        
        self.messagePopover = [[UIPopoverController alloc] initWithContentViewController:self.myMessage];
        [self.messagePopover presentPopoverFromRect: clickMe.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        
    } else {
     
        [self.messagePopover dismissPopoverAnimated:YES];
        self.messagePopover = nil;
    }
}
@end
